# -*- coding: utf-8 -*-

# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
from scrapy.pipelines.images import ImagesPipeline
from scrapy.http import Request


class ImagespiderPipeline(ImagesPipeline):
    """
    主要继承了scrapy的：ImagesPipeline这个类，我们需要在里面实现：
          def get_media_requests(self, item, info)
    这个方法主要是把蜘蛛yield过来的图片链接执行下载
    """
    def get_media_requests(self, item, spider):
        # 循环每一张图片地址下载，若传过来的不是集合则无需循环直接yield
        for img_url in item['img_url']:
            yield Request(img_url)
